from django.db import models


class HistoryManager(models.Manager):
    def archive(self, original, user=None, ip=None):
        chronicle = self.model(hst_original=original, hst_user=user, hst_ip=ip)
        for k, v in original.__dict__.iteritems():
            if k == 'id':
                continue
            if hasattr(chronicle, k):
                setattr(chronicle, k, v)
        chronicle.hst_revision = self.count() + 1
        chronicle.save()
